<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>微博详情</h1>
<div>
    <h2>
        {{weibo.nickname}}说:{{weibo.content}}
    </h2>
    <img :src="weibo.url" width="200" alt="">
    <hr>
    <h1>评论</h1>
    <input type="text" placeholder="说点儿什么..." v-model="comment.content">
    <input type="button" value="发表评论" @click="send()">
    <hr>
    <div v-for="item in commentArr">
        <h2>
            {{item.nickname}}评论说:{{item.content}}
        </h2>
    </div>
</div>


<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: 'body>div',
        data: {
            weibo: "",
            comment: {
                content: "",
                weiboId:""
            },
            commentArr: ""
        },
        methods: {
            send() {
                axios.post("/comment/insert", v.comment).then(function (response) {
                    if (response.data == 1) {
                        alert("评论成功!")
                        location.reload()
                    } else {
                        alert("请先登录")
                        location.href = '/login.html'
                    }

                })
            }
        },
        created: function () {

            v.comment.weiboId = v.weibo.id
            axios.get("/weibo/selectById" + location.search).then(function (response) {
                v.weibo = response.data
            }),
            axios.get("/comment/selectAllByWeiboId?id="+location.search.substring(4)).then(function (response) {
                console.log(response.data)
                v.commentArr = response.data
            })

        }
    })
</script>
</body>
</html>